<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*,com.baizhi.entity.*" isErrorPage="true" errorPage="/managerLoginJsp.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<title>商品列表</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/style.css" />
		<script>
			function deleteProduct(id){
				var del = window.confirm("确认删除吗？");
				if(del){
					window.location.href = "${pageContext.request.contextPath }/pro/deleteProduct?id=${p.id}"+id;
				}
			}
			function checkAll(){
				var main = document.getElementById("main");
				var ids = document.getElementsByName("ids");
				if(main.checked){
					for(var i = 0; i < ids.length; i++){
						ids[i].checked = true;
					}
				}else{
					for(var i = 0; i < ids.length; i++){
						ids[i].checked = false;
					}
				}
			}
			function ifChecked(){
				var ids = document.getElementsByName("ids");
				var main = document.getElementById("main");
				for(var i = 0; i < ids.length; i++){
					if(!ids[i].checked){
						main.checked = false;
						 return;
					}
				}
				main.checked = true;
			}
			function del(){
				var ids = document.getElementsByName("ids");
				var count = 0;
				for(var i = 0; i < ids.length; i++){
					if(ids[i].checked){
						count++;
					}
				}
				if(count == 0){
					window.alert("至少选中一个");
					return false;
				}else{
					return true;
				}
			}
			function delOk(){
				
			}
		</script>
	</head>
	<body>
		
		<div id="wrap">
			<div id="top_content"> 
				<div id="header">
					<div id="rightheader">
						
					</div>
					<div id="topheader">
						<h1 id="title">
							<a href="">商品管理</a>
						</h1>
					</div>
					<div id="navigation">
					</div>
				</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						欢迎
					</h1>
					
					<table class="table">
						<tr class="table_header">
							<td>
								<form action="${pageContext.request.contextPath }/pro/deleteMore" method="post" onsubmit="return del()">
								<input type="checkbox" onclick="checkAll()" id="main" />
							</td>
							<td>
								商品名
							</td>
							<td>
								单价
							</td>
							<td>库存</td>
							<td>状态</td>
							<td>
								商品描述
							</td>
							<td>
								操作
							</td>
						</tr>
						<c:forEach items="${list }" var="p" varStatus="a">
						<tr class="row1">
							<td>
								<input type="checkbox" name="ids" value="${p.id}" onclick="ifChecked()"/>
							</td>
							<td>
								${p.name }
							</td>
							<td>
								${p.price }￥
							</td>
							<td>${p.account }</td>
							<td>
							<c:if test="${p.status == 1 }"><font color="red">下架</font></c:if>
							<c:if test="${p.status == 0 }">上架</c:if>
							</td>
							<td>
								${p.description }
							</td>
							<td>
								<a href="javascript:void(0)" onclick="return deleteProduct(${p.id})">删除</a>&nbsp;<a href="${pageContext.request.contextPath }/pro/selectById?id=${p.id}">修改</a>&nbsp;
								<a href="${pageContext.request.contextPath }/pro/UpDownProduct?id=${p.id}">
								<c:if test="${p.status == 1 }">上架</c:if>
								<c:if test="${p.status == 0 }"><font color="red">下架</font></c:if>
								</a>
							</td>
						</tr>
						</c:forEach>
					</table>
					<input type="submit" value="删除勾选项" />


					<div><br /></div>
					</form>
					<p>
						<!--分页导航开始-->
						<c:if test="${pageIndex>=2 }">
							<a href="${pageContext.request.contextPath }/bean/bookListJsp?pageIndex=${pageIndex-1}&categoryId=${categoryId}">上一页</a>
						</c:if>
						<c:if test="${pageIndex<=1 }">
							上一页
						</c:if>

						第${pageIndex}页/共${totalPage}页

						<c:if test="${pageIndex<totalPage}">
							<a href="${pageContext.request.contextPath }/bean/bookListJsp?pageIndex=${pageIndex+1}&categoryId=${categoryId}">下一页</a>
						</c:if>
						<c:if test="${pageIndex>=totalPage}">
							下一页
						</c:if>
						<a href="${pageContext.request.contextPath }/product/addProduct.jsp" class="button"><input type="button" value="添加商品"/></a>
					</p>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
				www.zparkhr.com.cn
				</div>
			</div>
		</div>
	</body>
</html>
